package com.jinwei.qunguanjia.common.core.domain;

import com.jinwei.qunguanjia.common.enums.HttpResponseEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * 公共响应类
 *
 * @author yuanzs
 */
@Data
public class Response<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;
    private String msg;
    private T data;

    private Response(String code, String  msg) {
        this.code = code;
        this.msg = msg;
    }

    private Response(String code, String msg, T t) {
        this.code = code;
        this.msg = msg;
        this.data = t;
    }

    public static Response success() {
        return new Response<>(HttpResponseEnum.SUCCESS.getCode(), HttpResponseEnum.SUCCESS.getDesc());
    }

    public static <T> Response<T> success(T t) {
        return new Response<>(HttpResponseEnum.SUCCESS.getCode(), HttpResponseEnum.SUCCESS.getDesc(), t);
    }

    public static Response fail() {
        return new Response<>(HttpResponseEnum.INTERNAL_SERVER_ERROR.getCode(), HttpResponseEnum.INTERNAL_SERVER_ERROR.getDesc());
    }

    public static Response<String> fail(String msg) {
        return new Response<>(HttpResponseEnum.INTERNAL_SERVER_ERROR.getCode(), msg);
    }

    public static Response fail(String code, String  msg) {
        return new Response<>(code, msg);
    }

}
